<?php
if (count($rows) > 0) {
	$hidden = false;//loading from merchant account
	$anonymous_lbl = BUtils::T('anonymous_lbl');
	$points_s_lbl = BUtils::T('points_s_lbl');
	$visits_lbl = BUtils::T('visits_lbl');
?>
<div class="text-right" style="background:#e6e6e6;">
	<a href="javascript:;" onclick="suggestClose(this)" class="btn btn-link btn-mini btn-close" style="text-decoration:none;"><i class="icon-remove"></i></a>
</div>
<table class="table table-striped table-hover table-customer" style="margin-bottom:0;">
	<tbody>
<?php
foreach ($rows as $r) {
	$visit_timeago = Yii::app()->format->timeago((int)$r['ts_last_time']);
	$visit_time = Yii::app()->locale->dateFormatter->formatDateTime($r['ts_last_time'], null, 'short');
	$visit_info = BUtils::T('last_visited_lbl', array('{time_ago}'=>$visit_timeago))  . ' ('.$visit_time.')';
	if (empty($r['id_user'])) {
		$cust_name = $anonymous_lbl;
		$cust_url = Yii::app()->baseUrl . '/img/user-128.png';
		$cust_contact = '';
	} else {
		//set user name
		if (!empty($r['name'])) $cust_name = substr($r['name'], 0, strpos($r['name'], ' '));
		else $cust_name = $anonymous_lbl;
		
		//set active phone number/email
		$cust_contact = '<ul class="icons-ul">';
		if (!empty($r['mobile'])) {
			$cust_contact .= '<li><i class="icon-li icon-phone"></i> ' . CustomerHelper::getMobile($r['mobile'], $hidden) . '</li>';
		}
		if(!empty($r['email'])) {
			$cust_contact .= '<li><i class="icon-li icon-envelope-alt"></i> ' . CustomerHelper::getEmail($r['email'], $hidden) . '</li>';
		}
		$cust_contact .= '</ul>';
		
		//set user picture
		if (empty($r['picture'])) $cust_url = Yii::app()->baseUrl . '/img/user-128.png';
		else $cust_url = $r['picture'];
	}
	
	//amount + points + redeemed points
	$points = Yii::app()->locale->numberFormatter->formatDecimal($r['point']);
?>
<tr onclick="suggestSelected(this);" style="cursor:pointer;" data-id="<?php echo $r['id_user']; ?>">
	<td class="user">
		<img src="<?php echo $cust_url; ?>" alt="" onerror="this.onerror=null;this.src='<?php echo Yii::app()->baseUrl; ?>/img/user-128.png';" />
	</td>
	<td class="uinfo">
		<div class="cust-name">
			<span class="blue"><?php echo $cust_name; ?></span>
		</div>
		<div class="cust-contact"><?php echo $cust_contact; ?></div>
		<div class="visit-time"><?php echo $visit_info; ?></div>
	</td>
	<td class="uvisits">
		<div class="center text-big blue">
			<?php echo $r['visit_times']; ?>
		</div>
		<div class="center"><?php echo $visits_lbl; ?></div>
	</td>
	<td class="upoints">
		<div class="center text-big blue">
			<?php echo $points; ?>
		</div>
		<div class="center"><?php echo $points_s_lbl; ?></div>
	</td>
</tr>
<?php } ?>
	</tbody>
</table>
<?php } ?>